package xuegao.study.mall.admin.controller;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xuegao.study.mall.admin.feign.UmsMenuClient;
import xuegao.study.mall.common.api.CommonPage;
import xuegao.study.mall.common.api.CommonResult;
import xuegao.study.mall.common.model.ums.UmsMenu;
import xuegao.study.mall.common.vo.ums.UmsMenuVo;

import java.util.List;

@RestController
@RequestMapping("/menu")
public class UmsMenuController {

    @Autowired
    private UmsMenuClient umsMenuClient;

    @GetMapping("/list/{parentId}")
    public CommonResult<CommonPage<UmsMenu>> listMenu(
            @PathVariable("parentId") Long parentId,
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                       @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
        return umsMenuClient.listMenu(parentId, pageNum, pageSize);
    }

    @GetMapping("/treeList")
    public CommonResult<List<UmsMenuVo>> treeList() {
        return umsMenuClient.treeList();
    }

    @ApiOperation("根据id获取菜单详情")
    @GetMapping("/{id}")
    public CommonResult<UmsMenu> getMenu(@PathVariable("id") Long id) {
        return umsMenuClient.getMenu(id);
    }

    @ApiOperation("创建菜单")
    @PostMapping("/create")
    public CommonResult<Integer> addMenu(@RequestBody UmsMenu menu) {
        return umsMenuClient.addMenu(menu);
    }

    @PostMapping("/update/{id}")
    public CommonResult<Integer> updateMenu(@PathVariable("id") Long id, @RequestBody UmsMenu menu) {
        return umsMenuClient.updateMenu(id, menu);
    }

    @DeleteMapping("/delete/{id}")
    public CommonResult<Integer> deleteMenu(@PathVariable("id") Long id) {
        return umsMenuClient.deleteMenu(id);
    }
}
